package com.ruoyi.supervise.service.impl;

import java.util.List;

import javax.xml.xpath.XPathConstants;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.supervise.domain.ProsCertiLogInnerText;
import com.ruoyi.supervise.domain.ProsCertificateInfo;
import com.ruoyi.supervise.domain.ProsCertificateInfoText;
import com.ruoyi.supervise.mapper.ProsCertificateInfoMapper;
import com.ruoyi.supervise.service.IProsCertificateInfoService;

import cn.hutool.core.util.XmlUtil;

/**
 * @ClassName: MyTestServiceImpl
 * @Description: 测试从数据源
 * @Author wtj
 * @DateTime 2020年3月9日 上午10:41:31
 */
@Service
@DataSource(value = DataSourceType.SLAVE)
public class ProsCertificateInfoServiceImpl implements IProsCertificateInfoService 
{
    @Autowired
    private ProsCertificateInfoMapper prosCertificateInfoMapper;

	@Override
	public List<ProsCertificateInfo> selectProsCertificateInfoByUnitProGuid(String unitProjectGuid) {
		// TODO Auto-generated method stub
		return prosCertificateInfoMapper.selectProsCertificateInfoByUnitProGuid(unitProjectGuid);
	}

	@Override
	public List<ProsCertiLogInnerText> selectProsCertiLogByProReviewGuid(String prospectReviewGuid) {
		// TODO Auto-generated method stub
		return prosCertificateInfoMapper.selectProsCertiLogByProReviewGuid(prospectReviewGuid);
	}

	@Override
	public String selectProsCertiLogByGuid(String guid) {
		// TODO Auto-generated method stub
		return prosCertificateInfoMapper.selectProsCertiLogByGuid(guid);
	}

	@Override
	public ProsCertificateInfoText selectProsCertiLogTxtByGuid(String guid) {
		String CertificateTextStr = prosCertificateInfoMapper.selectProsCertiLogByGuid(guid);
		ProsCertificateInfoText pcit = new ProsCertificateInfoText();
		if(!StringUtils.isEmpty(CertificateTextStr)) {
			Document docResult=XmlUtil.readXML(CertificateTextStr);
			Object projectName = XmlUtil.getByXPath("//PsDataPacket/ProjectName", docResult, XPathConstants.STRING);
			pcit.setProjectName(String.valueOf(projectName));
			Object chUnitProject = XmlUtil.getByXPath("//PsDataPacket/ChUnitProject", docResult, XPathConstants.STRING);
			pcit.setChUnitProject(String.valueOf(chUnitProject));
			Object certificateNum = XmlUtil.getByXPath("//PsDataPacket/CertificateNum", docResult, XPathConstants.STRING);
			pcit.setCertificateNum(String.valueOf(certificateNum));
			Object buildAddress = XmlUtil.getByXPath("//PsDataPacket/BuildAddress", docResult, XPathConstants.STRING);
			pcit.setBuildAddress(String.valueOf(buildAddress));
			Object grProSurGrade = XmlUtil.getByXPath("//PsDataPacket/GrProSurGrade", docResult, XPathConstants.STRING);
			pcit.setGrProSurGrade(String.valueOf(grProSurGrade));
			Object buildArea = XmlUtil.getByXPath("//PsDataPacket/BuildArea", docResult, XPathConstants.STRING);
			pcit.setBuildArea(String.valueOf(buildArea));
			Object buildCompany = XmlUtil.getByXPath("//PsDataPacket/BuildCompany", docResult, XPathConstants.STRING);
			pcit.setBuildCompany(String.valueOf(buildCompany));
			Object buildPerson = XmlUtil.getByXPath("//PsDataPacket/BuildPerson", docResult, XPathConstants.STRING);
			pcit.setBuildPerson(String.valueOf(buildPerson));
			Object buildTel = XmlUtil.getByXPath("//PsDataPacket/BuildTel", docResult, XPathConstants.STRING);
			pcit.setBuildTel(String.valueOf(buildTel));
			Object proCompany = XmlUtil.getByXPath("//PsDataPacket/ProCompany", docResult, XPathConstants.STRING);
			pcit.setProCompany(String.valueOf(proCompany));
			Object proApiGrade = XmlUtil.getByXPath("//PsDataPacket/ProApiGrade", docResult, XPathConstants.STRING);
			pcit.setProApiGrade(String.valueOf(proApiGrade));
			Object gruRegister = XmlUtil.getByXPath("//PsDataPacket/GruRegister", docResult, XPathConstants.STRING);
			pcit.setGruRegister(String.valueOf(gruRegister));
			Object projectPin = XmlUtil.getByXPath("//PsDataPacket/ProjectPin", docResult, XPathConstants.STRING);
			pcit.setProjectPin(String.valueOf(projectPin));
			Object repWorkOut = XmlUtil.getByXPath("//PsDataPacket/RepWorkOut", docResult, XPathConstants.STRING);
			pcit.setRepWorkOut(String.valueOf(repWorkOut));
			Object proPerson = XmlUtil.getByXPath("//PsDataPacket/ProPerson", docResult, XPathConstants.STRING);
			pcit.setProPerson(String.valueOf(proPerson));
			Object examineDate = XmlUtil.getByXPath("//PsDataPacket/ExamineDate", docResult, XPathConstants.STRING);
			pcit.setExamineDate(String.valueOf(examineDate));
			Object projectOverview = XmlUtil.getByXPath("//PsDataPacket/ProjectOverview", docResult, XPathConstants.STRING);
			pcit.setProjectOverview(String.valueOf(projectOverview));
			Object reviewExperts = XmlUtil.getByXPath("//PsDataPacket/ReviewExperts", docResult, XPathConstants.STRING);
			pcit.setReviewExperts(String.valueOf(reviewExperts));
			Object technicalManager = XmlUtil.getByXPath("//PsDataPacket/TechnicalManager", docResult, XPathConstants.STRING);
			pcit.setTechnicalManager(String.valueOf(technicalManager));
			Object legalRepresentative = XmlUtil.getByXPath("//PsDataPacket/LegalRepresentative", docResult, XPathConstants.STRING);
			pcit.setLegalRepresentative(String.valueOf(legalRepresentative));
			Object reviewUnitName = XmlUtil.getByXPath("//PsDataPacket/ReviewUnitName", docResult, XPathConstants.STRING);
			pcit.setReviewUnitName(String.valueOf(reviewUnitName));
			Object acceptedNo = XmlUtil.getByXPath("//PsDataPacket/AcceptedNo", docResult, XPathConstants.STRING);
			pcit.setAcceptedNo(String.valueOf(acceptedNo));
			Object proCertifiateNum = XmlUtil.getByXPath("//PsDataPacket/ProCertifiateNum", docResult, XPathConstants.STRING);
			pcit.setProCertifiateNum(String.valueOf(proCertifiateNum));
		}
		return pcit;
	}
}
